package helloworld.admin.service.course;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import helloworld.admin.bean.CourseAdminBean;
import helloworld.dao.CourseDao;
import helloworld.dao.DAOException;
import helloworld.dao.DAOFactory;
import helloworld.example.exception.ErrorLevel;

/** 
 * @author TUYEN-DM
 *         <p>
 *         2009/05/09
 *         </p>
 *         <p>
 *         CourseListService provides the Service of Listing Courses.
 * It is also an example of Session Facade pattern.
 * In real projects, CourseListService is implemented as Stateful Session EJB.
 *         </p>
 */
public class CourseListService 
{

	public CourseAdminBean[] findCourses(String centerName) throws CourseListServiceException
	{
		CourseAdminBean[] customers = null;
		try
		{
			DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.MS_ACCESS);
			CourseDao dao = daoFactory.getCourseDAO();
			customers = dao.find(centerName);
		}
		catch (DAOException de)
		{
			if (! de.isLogged())
			{
				Log log = LogFactory.getLog("CourseListService");
				de.log(log);
			}
			throw new CourseListServiceException(de.getUserMessageKey(), 
									de.getValueReplacementArray(),
									de.getUniqueID(), 
									ErrorLevel.ERROR);
		}
		
		return customers;
	}

}